SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict khuramyz's Avatar
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CodeIgniter: Help in include files

    Hi,

    I am a totally noob in CI. I am sure there are people on this forum who are good at CodeIgniter. Please bear with me. I have a petty set of problems which I am finding answers for if I am to stick with CI.

    Every page has many parts. Header, Footer, Images, CSS, Config Variables (my own not CIs). My questions are

    1. If a page has Header and Footer, do I make model-view-controller set for each of them.

    2. If yes then this is definitely time consuming.

    3. If no, where(location inside the application folder) to make my Include folder where I can put the header, footer files.

    4. Can I use the Database class in these include (header,footer, category list) php files directly without going through MVC everytime.

    5. How to include these files in my main MVC page.

    6. Since these file will be needed on more than one pages, how can I make them global with the option to include them at some places and not include them some places.

    7. Where to put my CSS, Images and .js files. Should I put them on the document root.

    8. The config variables I need like site title, contact us email etc. are going to be loaded from the database. How can I do that, Iím basically stuck with file inclusion and going through MVC for each step.

    9. Can anyone please provide me with a sample set of files just to get me acquainted with the heirarchy.

    I hope these questions make sense. I am using CI 1.7 on PHP4. My URL is like http://localhost/site/. I have managed to hide the index.php through htaccess though. smile

    A timely reply would be greatly appreciated.

    Best Regards

    Khuram
    Khuram Javaid
    PHP Developer and Entrepreneur
    http://www.phprad.com/

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I hate doing this, more so when you obviously invested time in compiling your post, but all your questions are answered in the CI Documentation.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict khuramyz's Avatar
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew my brother would come to my aid.
    I came here after reading about 30 pages of documentation.
    I am sure you can do better than that. please
    Khuram Javaid
    PHP Developer and Entrepreneur
    http://www.phprad.com/

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You're persistent, I'll give you that.

    You can include multiple partial views in any view, so yes, you can use the same header and footer for example in every page.

    You place all view elements partial or otherwise in the views folder.

    You should not use the database layer inside the view, doing so would violate the point of using the MVC principle in the first place. I'm not even entirely sure you can, even if you wanted too.

    Remember, ALL data must be obtained with a model, and passed by the controller to the view.

    All CSS, JS and images must be placed in your public root, remember to use CI's base_url() function in your view to help you set the paths to these files in your views.

    I'm unsure of what you mean with regards to your config statement.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Addict khuramyz's Avatar
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehehe Thanks
    Never mind about config, I have got some replies on my thread over at CI forum
    I think i can give it a shot now.
    Much thanks Silver.
    Khuram Javaid
    PHP Developer and Entrepreneur
    http://www.phprad.com/

  6. #6
    SitePoint Addict khuramyz's Avatar
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Believe me, Thanks to the Al-Mighty,

    Its starting to make sense.
    Much thanx to you too.
    Khuram Javaid
    PHP Developer and Entrepreneur
    http://www.phprad.com/

  7. #7
    SitePoint Addict khuramyz's Avatar
    Join Date
    Oct 2005
    Location
    Manchester, UK
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is only one thing that i havent been able to understand.
    Lets say on my template page, I have to load a list of categories in a table.

    Ideally there should be a controller for template which can be called from anyother control to initialize the stuff.
    I havent been able to find this out anywhere.
    Right now, I am having to do this in every new page that I make.

    PHP Code:
    $this->load->model('template/template','TemplateFunctions'TRUE);
    $data['cats'] = $this->TemplateFunctions->get_categories();
    $this->load->view('template/template'$data); 
    Ideally this is not the best situation. Please advice me into how to make a master control which I include in every control and it knows how to react.
    Khuram Javaid
    PHP Developer and Entrepreneur
    http://www.phprad.com/


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •