<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">

    <title type="text">MtheoryX</title>
    <subtitle type="text">MtheoryX:Tutorials by Geeks, for Geeks</subtitle>
    <link rel="alternate" type="text/html" href="http://www.mtheoryx.com/" />
    <link rel="self" type="application/atom+xml" href="http://www.mtheoryx.com/index.php/site/atom/" />
    <updated>2008-03-21T18:26:52Z</updated>
    <rights>Copyright (c) 2007, MtheoryX</rights>
    <generator uri="http://expressionengine.com/" version="1.6.1">ExpressionEngine</generator>
    <id>tag:mtheoryx.com,2007:11:25</id>


    <entry>
      <title>Multiple views and templating with CodeIgniter: Method 2</title>
      <link rel="alternate" type="text/html" href="http://www.mtheoryx.com/index.php/site/multiple_views_and_templating_with_codeigniter_method_2/" />
      <id>tag:mtheoryx.com,2007:/1.33</id>
      <published>2007-11-25T03:41:00Z</published>
      <updated>2008-03-21T18:26:52Z</updated>
      <author>
            <name>MtheoryX</name>
            <email>drpoindexter@gmail.com</email>
            <uri>http://www.livemediaproductions.com</uri>      </author>

      <category term="Instructions"
        scheme="http://www.mtheoryx.com/index.php/site/C5/"
        label="Instructions" />
      <content type="html"><![CDATA[
         <p>With that said, lets move onto an interesting situation. Let's suppose you've set up a view which has a header, navigation, content, sidebar, ad unit, and a footer.</p>
<p>So, your view, with all the includes, would look something like this:</p>
<blockquote>
  <p>&lt;$this-&gt;load-&gt;view('partials/header');&gt;<br />
  &lt;$this-&gt;load-&gt;view('partials/nav');&gt;<br /><br />
&lt;div id="content"&gt;<br /><br />
&lt;h2&gt;Some content here.&lt;/h2&gt;<br /><br />
&lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam hendrerit orci commodo tortor. Nam eu lacus in turpis placerat pulvinar. Mauris vehicula nisi posuere magna. Aliquam a purus quis pede volutpat commodo. Fusce rutrum tortor non massa. Quisque non tortor. Duis adipiscing pretium velit. Maecenas a ante. Vivamus id urna. Nulla facilisi.&lt;/p&gt;<br />
&lt;/div&gt;<br /><br />

  &lt;$this-&gt;load-&gt;view('partials/sidebar');&gt;<br />
  &lt;$this-&gt;load-&gt;view('partials/ad');&gt;<br />
  &lt;$this-&gt;load-&gt;view('partials/footer');&gt;<br /></p>
</blockquote>
<p>And the controller index function would simply be this:</p>
<blockquote>
  <p>function index ()<br />
  {<br />
  &lt;$this-&gt;load-&gt;view('home');&gt;<br />
  }</p>
</blockquote>
<p>Notice that I obviously am keeping all the sub-views, or partials, in a folder together. This is just for organizational purposes, and you don't really have to do it...but you should <img src="http://www.mtheoryx.com/images/smileys/wink.gif" width="19" height="19" alt="wink" style="border:0;" /></p>
<h3>Disclaimer!! Important!!</h3>
<p>Now, before all you MVC crazies out there start hammering me with complaints like "You shouldn't have logic in the view" and "You're breaking MVC and promoting bad programming" let me set one thing straight. The logic that will be in the view is display logic. The "V" in MVC is for the view, or presentation of data. We will be actually making the decision in the controller. So the actually programmatic logic is, in fact, in the controller. However, the result of said logic happens in the view, as it should. So, disclaimer over, lets move on, shall we?</p>
<h3>Moving on...</h3>
<p>Okay, adding a little logic to our view; here's the situation: You have this sidebar view and this ad view. We're going to set up a little logic to let the view decide when the ad gets loaded into the view. The reason could be that you have a public site that serves an ad, but logged-in, registered users get an ad-free experience. Regardless, the point is, you can see how this works with this example.</p>
<p>You can easily extend the logic to say that non-logged in users get an ad and a sidebar, but logged in users get a control panel and a sidebar. Of course, you'd want to make sure for your layout, spacing, and all that you use classes. That way, when you replace something in the sidebar, its fluid and consistent. See how useful this can be?</p>
<h3>Something very basic...</h3>
<p>Okay, for now, lets start with something basic. We're going to set up an array called data, and we will assign an item in that array. The key will be "loggedIn" and we will manually set the value to "true."</p>
<p>In the controller, you'll have this:</p>
<blockquote>
  <p>function index ()<br />
  {<br />
  $data['loggedIn'] = 'true';<br />
  $this-&gt;load-&gt;view('home', $data);<br />
  }</p>
</blockquote>
<p>And in the view, you'll put this around your call for the ad:</p>
<blockquote>
  <p>&lt;?if ($loggedIn != "true") { ?&gt;<br />
  &lt;?=$this-&gt;load-&gt;view('partials/ad')?&gt;<br />
  &lt;? }?&gt;</p>
</blockquote>
<p>Now, what you'll notice is since we set the value to "true," the ad does not load! However, go back in the controller and change the value to "false" or, better yet, leave it empty. Now you will see the ad presented.</p>
<h3>Okay, where's this "extensible" bit? Right here...</h3>
<p>Remember I told you we could extend this? Okay, let me show you how to do that.</p>
<p>First, lets add another view file called "admin.php," and add a call for it in the view:</p>
<blockquote>
  <p>&lt;?=$this-&gt;load-&gt;view('admin')?&gt;<br /></p>
</blockquote>
<p>Now, we're going to expand on the logic that we put in the view. What we want is instead of a non-logged in user seeing an ad, we want the logged-in users to see their little control panel. It should look like this:</p>
<blockquote>
  <p>&lt;?if ($loggedIn != "true") {?&gt;<br />
  &lt;?=$this-&gt;load-&gt;view('partials/ad')?&gt;<br />
  &lt;?} else {?&gt;<br />
  &lt;?=$this-&gt;load-&gt;view('partials/admin')?&gt;<br />
  &lt;?}?&gt;</p>
</blockquote>
<p>Now, if you have the value set to "true" you will see the sidebar and your admin panel. And if you are not logged in, you will see the sidebar and an ad.</p>
<h3>In closing...</h3>
<p>So, this concludes our discussion on view logic. As you can see, this method is very flexible. If you use your imagination, I'm confident you can extend this technique much, much further.</p>
<p>In the next article in the series, I'll describe another method that allows for controlling all this decision logic inside the controller.</p>

      ]]></content>
    </entry>

    <entry>
      <title>ExpressionEngine Users: RSS Patch required</title>
      <link rel="alternate" type="text/html" href="http://www.mtheoryx.com/index.php/site/expressionengine_users_rss_patch_required/" />
      <id>tag:mtheoryx.com,2007:/1.32</id>
      <published>2007-11-23T21:06:00Z</published>
      <updated>2007-11-25T02:38:42Z</updated>
      <author>
            <name>MtheoryX</name>
            <email>drpoindexter@gmail.com</email>
            <uri>http://www.livemediaproductions.com</uri>      </author>

      <category term="News"
        scheme="http://www.mtheoryx.com/index.php/site/C2/"
        label="News" />
      <content type="html"><![CDATA[
         <blockquote>
<p>
  <code>system &gt; core &gt; core.output.php</code> file
</p>
</blockquote>
<p>So, after replacing that file, the feed is valid....except for one thing...</p>
<p>You'll still get this error:</p>
<blockquote>
<p>
  <code>line 33, column 4: Missing atom:link with rel="self"</code>
</p>
</blockquote>
<p>Just ignore this. Your feed is valid...this is not an error, it's a recommendation by the authors of the validator. Apparently they are wanting you to use the Atom namespace to get at some features that you can't get with RSS 2.0. Politics.</p>
<p>Further explanation of this, and discussion can be found <a href="http://expressionengine.com/forums/viewthread/64925/P18/">in this forum</a> thread on the EE boards.</p>


      ]]></content>
    </entry>

    <entry>
      <title>Multiple views and templates with Code Igniter: Method 1</title>
      <link rel="alternate" type="text/html" href="http://www.mtheoryx.com/index.php/site/multiple_views_and_templating_with_code_igniter_method_1/" />
      <id>tag:mtheoryx.com,2007:/1.31</id>
      <published>2007-11-23T16:48:00Z</published>
      <updated>2007-11-25T02:17:47Z</updated>
      <author>
            <name>MtheoryX</name>
            <email>drpoindexter@gmail.com</email>
            <uri>http://www.livemediaproductions.com</uri>      </author>

      <category term="Instructions"
        scheme="http://www.mtheoryx.com/index.php/site/C5/"
        label="Instructions" />
      <content type="html"><![CDATA[
         <h3>The basics:</h3>
<p>First, let's explain some basics: <a href="http://codeigniter.com">CodeIgniter</a> (CI) is an <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC</a> PHP framework. It is derived from <a href="http://expressionengine.com">ExpressionEngine</a> and is quite flexible. Not as strict an implementation of MVC as something like CakePHP would be, CI still follows a set of defaults, and understanding the concepts behind these defaults is key.</p>
<p>Let's take a peek at the <a href="http://codeigniter.com/user_guide/libraries/loader.html">CI User Guide</a> for a moment. When you render a view from your controller, what you are doing, essentially, is passing program control from the controller to the view. In the MVC model, this means moving into the presentation and interaction part of the model.</p>
<p>So, in your controller, you would have:</p>
<blockquote>
<p>
  <code>$this-&gt;load-&gt;view('yourView');</code>
</p>
</blockquote>
<p>And you will have a view named "yourView.php"</p>
<h3>Now, how about those time-saving templates?</h3>
<p>This is the method to call the view. Now, lets say that you want all your views to have some shared elements. For example, on this site, the header, sidebar, and footer are the same on ever page. It would be silly to actually put that code in every view.</p>
<p>What if you got the site all done, and had 20 different view files. And suppose you realized that one of the links you added to your sidebar was wrong. Yeah, now you see the point of separating your shared code.</p>
<p>So, in your view, instead of all that header stuff, create a file called "header.php" and place all of your header code in there.</p>
<p>After calling the "yourView.php" file, instead of all that header code, you would place this at the top of the view:</p>
<blockquote>
<p>
  <code>$this-&gt;load-&gt;view('header');</code>
</p>
</blockquote>
<p>This essentially performs an include, but does not pass program control to that view.</p>
<p>In the view you would essentially have this for a pretty standard site:</p>
<blockquote>
<p>
  <code>$this-&gt;load-&gt;view('header');</code><br />
  <code>$this-&gt;load-&gt;view('navigation');</code><br />
  <code>...put the content unique to this view here...</code><br />
  <code>$this-&gt;load-&gt;view('sidebar');</code><br />
  <code>$this-&gt;load-&gt;view('footer');</code><br />
</p>
</blockquote>
<p>So, this is the basic way to manage a pseudo-templating system with CI. In the next example in the series, I'll show you how to start adding some decision making for the occasion that you may have views that wont have a sidebar or a footer.</p>


      ]]></content>
    </entry>


</feed>