Need some help

#1
[eluser]Unknown[/eluser]
Hi, I'm quite experienced in PHP but this is the first time I have really considered using a framework like this.

I have a few questions about making a website more dynamic.

Okay, first question.

I know of course how I would go about making this sort of thing from scratch, but I just don't know the proper way of doing it with this framework. How would I go about making a dynamic title that can be called throughout the whole system like this in my templates:
Code:
<title>{site_title}</title>

Second question.
How do I go about loading classes in each one of my scripts without having to include them each time?

Thanks for any help.

#2
[eluser]Neocrypter[/eluser]
Hi, glad to see someone else that new to using the framework besides me Big Grin, First off my suggestion is if you are not used to MVC Models you should do some reading up on the theory behind them, Which will help answer both your questions I think.

you short tag example is for a template engine which CI dose not have built in there are several libraries available that you can include into your projects quickly to help with this, and a few really good examples on the forums here for that matter just do a search and im sure you will find a great starting point.

the way I am doing titles is im loading seperate veiws one that has the style.css title etc in it then it loads the working data set example

in my controller
Code:
$this->data['title']='Bann User';
         $this->data['page']='edit_banned_user_form';
     $this->data['query'] = $this->bu->get_entries($this->uri->segment(3));
         $this->load->view('template', $this->data);

template.php
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
    &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
    &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;css/style.css" type="text/css" media="screen" /&gt;
&lt;/head&gt;
&lt;body&gt;
    <div id="wrapper">      

        <div id="header">
          
        </div>

        <div id="main_content">
            &lt;?php //$this->load->view('menu'); ?&gt;
            &lt;?php $this->load->view($page); ?&gt;

        </div>

        <div id="footer">
            Copyright 2010. &lt;!-- or create a view and load here --&gt;
        </div>
            
    </div>
    
&lt;/body&gt;
&lt;/html&gt;

in the example im sending $this->data['page']='edit_banned_user_form'; to the template which it calls that as an additional view to be loaded and integrates it into the template.php like an include essentially

I actually found this method on the forums here Big Grin dont remember the author though

there are other ways, so id just look around and find what suits your needs and style.

#3
[eluser]pickupman[/eluser]
Your first question is used in the [url="http://ellislab.com/codeigniter/user-guide/libraries/parser.html"]parser class[/url]. This will allow you to interpret curly braces as pseudo variables.

You may [url="http://ellislab.com/codeigniter/user-guide/general/autoloader.html"]autoload[/url] any library, helper, model, config in /application/config/autoload.php. The great part of CI is the user guide. It will be very helpful.

#4
[eluser]Neocrypter[/eluser]
Oh thanks for that info Big Grin im sure that will come in handy later one. On a side not just looked through the links in your sig and wow those are very useful indeed.

#5
[eluser]pickupman[/eluser]
Thanks, they are something you could almost use in every project. I found myself posting links enough for this stuff, I though I might as well pimp some other people's code. You will find a lot of useful snippets on Phil's blog...great member of CI.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.