Welcome Guest, Not a member yet? Register   Sign In
Code Igniter noob :)
#21

[eluser]Mr. Gibon[/eluser]
can i get answer ?
#22

[eluser]srpurdy[/eluser]
[quote author="Mr. Gibon" date="1272466728"]can i get answer ?[/quote]

It doesn't make much difference in terms of how things function, but I would say it depends mostly on the size of your end project. If you plan on the web-site being quite large, it would be better to have things in different files so you can find what you need a lot easier.

This below is a simple function I wrote for templating my system based on controller and database. This allows me to have a completely unique looking website on any page on my site via a database. So it looks in a specific folder for the required files.

Code:
<?php class MY_Controller extends Controller
{
function MY_Controller()
{
    parent::Controller();
    $this->load->helper('date');
#Autoload main_web model in config/autoload.php
        $this->load->model('leagues_model');
    $menu = $this->main_web->get_menu();
    $template = $this->main_web->get_template();
    $construc = $this->main_web->config();
    $meta = $this->main_web->config();
    $sitename = $this->main_web->config();
    $data = array (
        'template' => $template,
        'menu' => $menu,
        'construc' => $construc,
        'meta' => $meta,
        'sitename' => $sitename
    );
        $this->_container = $this->config->item('FAL_template_dir'). $template;
    $this->load->vars($data);
}
}
?>

I took out lot of extra stuff I had for other reasons to keep it simple, but it's not hard to pass a database value to MY_Controller using a model.

Main Web Model
Code:
function get_template()
{
    $ci_template = $this->db->get('site_config');
    foreach ($ci_template->result() as $tmp)
    {
    $temp1 = 'template/themes/';
    $temp2 = $tmp->stylefilename;
    $temp3 = '/container';
    $tmpf = $temp1 . $temp2 . $temp3;
    }
    return $tmpf;

Leagues Model
Code:
function get_league_temp()
{
    $this->db->where('url_league_name', $this->uri->segment(3));
    $ilr_template = $this->db->get('ilr_league');
    foreach ($ilr_template->result() as $ilr_tmp)
    {
    $temp1 = 'template/themes/';
    $temp2 = $ilr_tmp->theme_name;
    $temp3 = '/container';
    $ilrtmp = $temp1 . $temp2 . $temp3;
    }
    return $ilrtmp;
}

function get_league_temp2()
{
    $this->db->where('url_league_name', $this->uri->segment(3));
    $ilr_template = $this->db->get('ilr_league');
    foreach ($ilr_template->result() as $ilr_tmp)
    {
    $temp1 = 'template/themes/';
    $temp2 = $ilr_tmp->theme_name;
    $ilrtmp2 = $temp1 . $temp2;
    }
    return $ilrtmp2;
}

At which point you can use a controller file to get that information like below.

Code:
$league_temp = $this->leagues_model->get_league_temp();
$league_temp2 = $this->leagues_model->get_league_temp2();
$data['page'] = $this->config->item('FAL_template_dir'). $league_temp2. '/sponsors_list';
$this->_container = $this->config->item('FAL_template_dir'). $league_temp;
$this->load->vars($data);
$this->load->view($this->_container);

Depending on your folder structure you can do this however you like, but that would give you complete control over the page design.

Inside that actual folder you have a file called container.php with

Code:
<?php
$this->load->view($this->config->item('FAL_template_dir').'template/themes/leagues/layout');
$this->load->view($this->config->item('FAL_template_dir').'template/themes/leagues/layout_bottom');
?>

As many files as you want to use for your layout.

I know it's got some limitations, it does what I need for the project I used it for, but maybe someone can find some of it useful. Smile

I know your new and this might be confusing right now, but thought I'd share it anyway. Smile

Shawn
#23

[eluser]Bart v B[/eluser]
[quote author="Mr. Gibon" date="1272331287"]Thanks for reply, i will probably use this Parser.

Still no answer for this: Is is a good way of building website based on code igniter, all in one controler like this

Code:
class Welcome extends Controller {

    function Welcome()
    {
     content here
    }
        function Offer()
    {
     content here
    }
    function Contact()
    {
     content here
    }
[/quote]

You don't want to do it this way Wink
Because, when youre webapplication gets lager, then it's to difficult to maintain this.

Then it's much easyer to make some sepperate controllers.

for example:

Main controller-> where you show the main content.
offer controller -> where for example there is a webshop.
Contact controller -> where you make options to get in contact.
#24

[eluser]Mr. Gibon[/eluser]
Thanks!

My problem is i cant find way to build website in CI, i konto it is great framework, and how to build some formas, and single page,but not website, all tutorials are about some other things but not this one Sad
#25

[eluser]Tominator[/eluser]
Hello Mr. Gibon,

CI is great because it gives a freedom of choice. It's up to you, if you make 10 controlers or 1 controller with 10 methods. So I think, you can make your website using CI, but you are looking for best way, how to do it, but it is hard to say best way, because everybody of us has another coding style.

After all I have one advice to you:
If you are making small site, choose 1 controller. If you are making big site, choose more controllers.

@srpurdy: you are making it too hard ...

Tom.
#26

[eluser]Mr. Gibon[/eluser]
this is the reply i was waiting for Smile
#27

[eluser]Bart v B[/eluser]
@Tominator, (hehe nice nickname Wink ) and Mr. Gibson

I not agree with you sorry.
What give you the freedom to just one single controller?
For the record i did not reat the whole topic, so maybe i misunderstoot the real problem.

If it is a small website you don't want to do everything in one controller.
It does not make any sence.

For example:

If you have one controller and the website has for example some main content, contactpage, and guestbook.
how in the world you can understand youre own controller.
A contactpage can send some information, but an guestbook also.

So a better method would be that there is a understanding how the framework works.
The first segment is the controller when it's called.
something like this: http://domain.tld/contact/

that should be not to complicated, because youre controller is contact.
With some code:
Code:
<?php

class Contact extends Controller
{

  //  this is caled if we go to contact/
  function index()
  {
    // we just simple output some html that is in your views folder caled contactpage.php
    $this->load->view('contactpage');
  }

}
CI allows you to use methods. So when you go to /contact/send/ then the controller is caled, and the method that we use is send.

some code
Code:
<?php

class Contact extends Controller
{

  //  this is caled if we go to contact/
  function index()
  {
    // we just simple output some html that is in your views folder caled contactpage.php
    $this->load->view('contactpage');
  }

  // this is the method that wel call if we want to send some data to the server
  function send()
  {
    // do something with the data
    // afther sending we load a new view
    $this->load->view('sendpage');
  }
}
As you see, this is a nicer and easyer way to use. just call a controller, if there is a method call it from the controller/method.

Hope that helps you Wink
#28

[eluser]Tominator[/eluser]
Yes you are true, but:
1. You can use models
2. You can use routers
3. You can use POST to current page

So you can make webpage by one controller or many controllers. Of course, it's up to you ... (I prefer many controllers, but it's just my opinion).

Tom.




Theme © iAndrew 2016 - Forum software by © MyBB