ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

WHERE DO I PUT MY PHP CODE?

April 09, 2012 8:14pm

Subscribe [3]
  • #1 / Apr 09, 2012 8:14pm

    gamebuilders

    2 posts

    I am lost for where I am actually suppose to put my php logic for front end web pages. I want to create a site that members login to that is not apart of the EE control panel and they get to see restricted content. I want to leverage the existing templating system in EE along with my custom views so that changing the design of the site is easy.  Normally in Codeigniter you just create a controller to store all your php logic and create a model class and a view file that is loaded by the controller. I have no idea how to do this in EE. Its really frustrating.

    I can drop php code in a template page which stores it in the db but that seems like a terrible place to put a bunch of code which is then tied to my view. Creating a plugin or module seems like it is directly related to the EE control panel or for writing a block of code that you want to parse something in a template. They just don’t seem to make sense for what it is I am trying to accomplish. Hopefully this post isn’t to confusing.

  • #2 / Apr 10, 2012 7:18pm

    Jeremy Latham

    74 posts

    Does this page help you at all?

    Login Form Tag

  • #3 / Apr 10, 2012 7:22pm

    Cem Meric

    210 posts

    I want to create a site that members login to that is not apart of the EE control panel and they get to see restricted content

    You don’t have to use php to achieve this. Just create member login and in your template if logged in user/member group matches your criteria show appropriate content. Here is starting point for you from the docs http://is.gd/PagXqQ

  • #4 / Apr 10, 2012 7:50pm

    gamebuilders

    2 posts

    I was hoping to be able to layout my code like such and still leverage the site wide headers, footers and includes like other pages on the site:

    //Possible EE directory layout of custom files
    /expressionengine
    -----/ controllers
    --------- mycustomdashboardController.php (will hold logic for displaying a view and also dealing with model data)
                         -Maybe the controller loads the header, footer, and template group.
    -----/ models
    --------- mycustomareaModel.php (handle whatever db changes and model logic I want here)
                        - I should be able to leverage the EE db functions and methods to alter the db here
    -----/ views
    --------- myscustomdashboardView.php (Add view logic here. Could be template content)


    From what I can gather so far this is not possible correct? If you want a custom page in EE you have to create a template group and dump all your custom code and html view data in one place which is either stored in the db or optionally in an html file and to me that sounds like a mess. Thoughts?

  • #5 / Apr 10, 2012 8:16pm

    Cem Meric

    210 posts

    Ok lets step back for a moment. What is your reason to use EE in the first place if you can get the results you want in CI already?

  • #6 / Apr 10, 2012 8:32pm

    gamebuilders

    2 posts

    Good question.

    I want to leverage all the other features of EE for authentication, configurable control panel, ability to write plugins and use community plugins for features that are already built. However, there is a section of the site that I need to be custom for creating a dashboard of analytics or allowing a logged in user to see a secured area of information that is read from a separate area of the db outside of EE data. No of these custom pages need to be configurable in EE but I still want to leverage the global variables from member groups and stuff like that. I still want the front end html portion to leverage the same header, footer and other includes that the rest of the EE site uses so that my custom pages still blend in with the rest of the site.

    I think I might have come up with a solution. I figured out how to turn off the routing of EE to allow me to create custom controllers like in a regular CodeIgniter install so I may just create my custom controllers and then create my view files as templates and do redirects between the two, but thats just annoying. It would have been nice to just use the same Codeigniter MVC paradigm along side an EE install and just pull in EE view includes and leverage it as I want to in custom areas of my site for example like:

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Dashboard extends CI_Controller {
    
     /**
     * Contsruct
     **/
    
     function __construct() {
    
      parent::__construct();
    
      // Initialize ExpressionEngine objects
      $this->core->_initialize_core();
      $this->EE =& get_instance();
    
     }
    
     /**
     * Index function
     * @return void
     **/
    
     function index() {
    
         //EE
                $this->EE->loadElement('HEADERSTUFF');
                $this->EE->loadElement('CUSTOMVIEWFILE');
                $this->EE->loadElement('FOOTERSTUFF');
     }
    
             function doSomethingFancy(){
             }
    }
    ?>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases