Welcome Guest, Not a member yet? Register   Sign In
help needed about logic.
#1

[eluser]demiRon[/eluser]
Hi;
i'm try to build new app. News Portal.

i want to make a class which is complete solution for site navigation.

i mean:

segments -> http:/xxxxx. com/content/maincategory/subcategory
Contents related with subcategory.

Code:
class Content extends Controller
{
function __construct()
{
  parent::Controller();
}

function index()
{
  // this is Main Category calls first SubCategory
  //some data array
  $this->parser->parse('theme/'.$theme.'/cont', $data);
}

function subcat($subcat)
{
  //some data array $subcat
  $this->parser->parse('theme/'.$theme.'/cont', $data);
}

}

Now; i get this values; but i want to get these values at begin.
i tried to move these in __constructor but i get many errors like "unexpected T_VARIABLE"
Code:
$cat  =$this->uri->segment(2, 0);
$acat =$this->uri->segment(3, 0);

Ps: sorry for my bad eng.
#2

[eluser]Tominator[/eluser]
Hi man!

I am using CI 1.7.2:

Find:
Code:
function __construct()
{
  parent::Controller();
}

Replace:
Code:
function Content()
{
  parent::Controller();

  $this->parser->parse('theme/'.$theme.'/cont', $data);

}

Now, FIND (in index() and subcat()) and DELETE:
Code:
$this->parser->parse('theme/'.$theme.'/cont', $data);
#3

[eluser]demiRon[/eluser]
Thanks Tominator;

it's good idea. i tried.
now problem is ->http:/xxxxx. com/content/maincategory/subcategory

Content ok.

but it's still wants to find "maincategory" fonction. Smile

how can we make it dynamic?
#4

[eluser]Tominator[/eluser]
Is index() your “maincategory” function.

If yes add to your function Content() these line:
Code:
$this->index();
#5

[eluser]demiRon[/eluser]
No, its not.
But i tried, it gives twice output Smile

it looks like;

Code:
class Content extends Controller
{
   function Content()
   {
    parent::Controller();

        $kat_seo    =$this->uri->segment(2, 0);
        $kat_id        =$this->_getkat_seo_to_id($kat_seo);

        $akat_seo    =$this->uri->segment(3, 0);
        $akat_id    =$this->_getakat_seo_to_id($akat_seo);    

        
        $tema            =$this->_tema();
        $alt_kategoriler     =$this->_alt_kategoriler($kat_id);
                
        $data = array(
        'tema'   => $tema,
        'tema_path' => base_url().'app/views/theme/'.$tema,
        'alt_kategoriler'=>$alt_kategoriler,
        'uri_kat'=>$kat_seo,
        'title'=>$this->_get_title($akat_seo),
        'content'=>$this->_get_content($akat_seo)
                              
               );

         $this->index();
   }

   function index()
   {
    //same Content fonc.

    $this->parser->parse('theme/'.$tema.'/detay', $data);

   }

//other foncs.
}

i think it's still tring to find maincategory segments fonc.
#6

[eluser]Tominator[/eluser]
Yes, if you call index(), like this: http://yoursite.com/controller/index then it show it twice (because it show it in constructor and method). You can delete line: $this->index() and please answer this questions:

What is your maincategory function? Where can I found it?

(btw. Where are you from?)
#7

[eluser]demiRon[/eluser]
from Turkey.

Now:

category table like -> id | cat_name | seo
sub-category table like -> id | cat_id | acat_name | seo
content table like -> id | cat_id | acat_id | txt | seo

now i try to call category/sub-category
so i havent to make many fonctions for every category if i can solve like this.
if not; i have to make each fonction for each category.

( + where r u from? Smile )
#8

[eluser]Tominator[/eluser]
I'm from Slovakia.

I think I understand Big Grin

You have to set to your routers.php (/application/config/) something like this:
Code:
$route['category/:any'] = $route['category/index/$1'];

Then when you cal:
http://yoursite/category/keyboard

It automaticaly redirect you to:
http://yoursite/category/index/keyboard

That means, that your controller will be 'Category', method 'index()' and uri segment 3 will be 'keyboard'.

Tom.
#9

[eluser]demiRon[/eluser]
ohh god!

i can do this with .htaccess modrewrite.

i try to find best solution.

Thanks for helping.
#10

[eluser]demiRon[/eluser]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /category/index/$1/$2 [L]

maybe like this Smile




Theme © iAndrew 2016 - Forum software by © MyBB