Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Recycling code

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
dendaak
Smarty n00b


Joined: 10 Mar 2013
Posts: 2

PostPosted: Tue Mar 12, 2013 3:15 pm    Post subject: Recycling code Reply with quote

Hello,

I like the way Smarty works but I would like to recycle my code better for other projects. Is there a way to use it more like 'modules'? For example I have to create a project with a login I can easy use my login function from an other project? Because the core code is always the same.

What is the best way/workflow to organise this?
Is using a MVC structure interesting? And if so, what is the best way to implement it?

Thanks a lot!
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Mar 12, 2013 5:39 pm    Post subject: Reply with quote

That would completely depend on your implementation of Smarty. It is certainly possible to do, but up to your implementation.
Back to top
View user's profile Send private message Visit poster's website
dendaak
Smarty n00b


Joined: 10 Mar 2013
Posts: 2

PostPosted: Tue Mar 12, 2013 6:07 pm    Post subject: Reply with quote

Currently I am creating projects the following way:



But I would like to have a way of doing it more effective, so I can easy recycle my code.

I want to make my way of programming faster and more logic.
Can anyone suggest me some tips?

Thanks

( my index file looks like this )
Code:

<?php
   session_start();
   require_once('classes/Config.php');
   require_once('classes/Common.php');
   require_once('classes/PHPErrorHandler.php');
   $config = new Config();
   set_error_handler('PHPErrorHAndler::handle');
   require_once('classes/VoedingSmarty.php');
   require_once('classes/VoedingPdo.php');
   require_once('classes/exceptions/CustomPDOException.php');
   
   // DAO Classes
   require_once('classes/DAO/DAOUsers.php');
   require_once('classes/DAO/DAOProducts.php');
   
   //var_dump($_SESSION['user']);
   
   $smarty = new VoedingSmarty();
   $content = "";
   $page =(isset($_GET['page'])) ? $_GET['page']: 'home';
   $action= (isset($_GET['action'])) ? $_GET['action']: '';
   $id= (isset($_GET['id'])) ? $_GET['id']: '';
   
   // FRONTCONTROLLER
   switch ($page) {
   
      default:
      {
         require_once('includes/login.php');
         if(isset($_POST['btnLogin']) && $action = 'validate')
         {
            $content = validateLogin();
         }
         else
         {
            $content = getContent();
         }
         break;
      }
      
      case "overview":
      {
         require_once('includes/overview.php');
         $content = getContent();
         break;
      }
      
      case "logout":
      {
         require_once('includes/logout.php');
         $content = getContent();
         break;
      }
      
      case "add":
      {
         require_once('includes/add.php');
         if(isset($_POST['btnAdd']) && $action = 'add_product')
         {
            $content = validateProduct();      
         }
         else
         {
            $content = getContent();
         }
         break;
      }
      
      case "zoeken":
      {
         require_once('includes/search.php');
         $content = getContent();
         break;
      }
      
      case "account":
      {
         require_once('includes/account.php');
         $content = getContent();
         break;
      }
      
   }
   
   $smarty->assign('page',$page);
   $smarty->assign('content',$content);
   $smarty->display('index.htm');
      
?>
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP