Welcome Guest, Not a member yet? Register   Sign In
Dynamic Content in CI
#12

[eluser]DJMOHNL[/eluser]
Hey.

i thought i might give you some suggestion with making dynamic php views.

Code:
<?php

class Test extends Controller {
  function Test() {
    parent::__construct();  
    
    // this is where you load your helper, library, or models.
    // you can also put them in your config file located on application/config/config.php
    
  }      

  function index() {
    
  }

  // this is a test function called myview, you can also rename it for your application
  // its only for showing you how i normally work.
  //$my2nd section is normally "NULL", this means it can be blank and showed as:
  // http://yoursite.com/test/mycontrol
  // it can be given a uri segment parameter this means that you can fill it in in your adressbar
  // and show a specific file (view file)
  // for example you want to see your "2nd article" you put in uri:
  // http://yoursite.com/test/mycontrol/2

function mycontrol($my2ndsection = NULL) {
    // this example without model. the best is to load it in the child controller construction (the function called "Test" above!)
    
    // here we tell the view file to use this variables to show the usere specific content
    $data['articleId'] = $this->uri->segment(3, 0);

    // here you load the view files and give the variables to it.
    // i personally create sections out of the view files, this means that my view files
    // keep cleaner and less heavy. the 1st view file is the header, 2nd your specific
    // controller view file, 3rd view is the footer.
    $this->load->view('header');// note this is the header file
    $this->load->view('yourAdditionalFolderName/YourViewFileName', $data);// your view
    $this->load->view('footer');// this is the footer
  }
}
?>

So now we have created a controller with a specific article id to show.
We can go on and make the view file and generat the content thats needed for your users.

So lets show the view file.
Code:
<?php
// here is the php function set to get the content the user wants.
// the $articleId is the shortTag version of the $data['articleId'] this is possible with // CodeIgniter
if($articleId = 1)
{
// make a code for showing the 1st articleId
// you can use a model file/function if its loaded.
echo "<h4>This is content 1, please read on.. and click on content 2 link</h4><br />";
}
if($aricleId = 2)
{
// put your code here to show articleId 2, as the 2nd article
// you can use a model file/function if its loaded.
echo "thanks for reading on.. and place your comments below in a comment box<br />";
}
?&gt;
// as my header has been loaded, i normally only have to put some like:
<div id="someid">
<p>

  This is the base content, you can choose a link to show the 2nd article.<br />
<a href="&lt;?=base_url('test/mycontrol/1')?&gt;">Go to article 1</a>

<a href="&lt;?=base_url('test/mycontrol/2')?&gt;">Go to article 2</a>

<a href="&lt;?=base_url('test/mycontrol/3')?&gt;">Go to article 3, wich currently doesnt exist</a>

</p>
</div>

So thats how i normally do it, its a professional way. Not completely explained, just show it shortly. It can be fast and professional with CI, if you just make sure it can be handled. You could try the 'try, catch, break' functionality of php inside CI to make it better to overlook it.

I hope you could use this, i prefer the way you use header, menu, controllerview and footer pages seperate. It just makes life easier!
:coolsmile:


Messages In This Thread
Dynamic Content in CI - by El Forum - 12-09-2009, 08:36 AM
Dynamic Content in CI - by El Forum - 12-09-2009, 08:45 AM
Dynamic Content in CI - by El Forum - 12-09-2009, 11:18 AM
Dynamic Content in CI - by El Forum - 12-09-2009, 11:29 AM
Dynamic Content in CI - by El Forum - 12-09-2009, 12:22 PM
Dynamic Content in CI - by El Forum - 12-09-2009, 01:11 PM
Dynamic Content in CI - by El Forum - 12-09-2009, 01:16 PM
Dynamic Content in CI - by El Forum - 12-11-2009, 03:30 AM
Dynamic Content in CI - by El Forum - 12-11-2009, 04:40 AM
Dynamic Content in CI - by El Forum - 12-11-2009, 01:11 PM
Dynamic Content in CI - by El Forum - 12-12-2009, 05:15 AM
Dynamic Content in CI - by El Forum - 12-20-2009, 11:20 PM
Dynamic Content in CI - by El Forum - 12-21-2009, 08:38 AM
Dynamic Content in CI - by El Forum - 12-21-2009, 09:31 AM
Dynamic Content in CI - by El Forum - 12-21-2009, 06:02 PM
Dynamic Content in CI - by El Forum - 12-21-2009, 06:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB