Welcome Guest, Not a member yet? Register   Sign In
I'm having trouble following the MVC standard.
#1

(This post was last modified: 03-24-2023, 01:18 AM by LieoUhlerredyh.)

I'm new to CodeIgniter and I may have made a silly mistake. I have a view called "menu.php" with several options, such as "Query" and "Registration". When I click on "Query", it should call the view "queryProducts.php", but it's not working. How can I call it from the menu? It worked fine without the framework, but I'm having omegle voojio shagle trouble following the MVC standard.
Reply
#2

(03-09-2023, 02:47 AM)LieoUhlerredyh Wrote: I'm new to CodeIgniter and I may have made a silly mistake. I have a view called "menu.php" with several options, such as "Query" and "Registration". When I click on "Query", it should call the view "queryProducts.php", but it's not working. How can I call it from the menu? It worked fine without the framework, but I'm having trouble following the MVC standard.

Hi

You can do if you following. 

In you controller you should have different methods for each view:

PHP Code:
// Assume this is your default view  and the route is /home
public function index(){
    return  
view('header')
    .
view('menu')
    .
view('somepage')
    .
view('footer');
}

// this would be your path /home/query
public function query(){
    return  
view('header')
    .
view('menu')
    .
view('queryProducts')
    .
view('footer');
}

// this would be /home/register
public funtion register(){
    return  
view('header')
    .
view('menu')
    .
view('register')
    .
view('footer');


I have assumed you would have the following view files in your Views folder:
- header.php
- footer.php
- menu.php
- queryProducts.php
- register.php
- somepage.php

I assume you can create links in your view file using site_url() as described here: https://codeigniter4.github.io/CodeIgnit...elper.html

Also please read: https://codeigniter4.github.io/CodeIgnit...pages.html
Reply
#3

(This post was last modified: 03-09-2023, 02:27 PM by captain-sensible.)

i do mostly everthing from routes .So suppose on dev localhost , I have a view displaying : http://127.0.0.7/blogArticle/Southhall-Church-Park

via

Code:
<a href = blogArticle/Southhall-Church-Park> Southhall-Church-Park         </a>

blogArticle is connected to a route and Southhall-Church-Park is a slug I have in a slug field of slug

in app/config/Routes.php i have :

Code:
$routes->get('blogArticle/(:segment)', 'Blog::showArticle/$1');


so in the above anything in a url with blogArticle is going to get picked up

whats on the left i.e the url section is going to get passed to a controller called Blog.php and processes in a function as follows
Code:
Blog::showArticle/$1


Code:
public function showArticle($theSlug)
                    
                    {
                                         
                    $handle = new BlogModel();
                    $result= $handle->getArticle($theSlug);
                        
                    $data =[
                    'title'=>$theSlug,
                    'blog'=>$result,
                    'date'=>$this->myDate
                    ];
                            
                        
                    echo view('blogArticle',$data);
                    
                        
                    
                    }

So you can design how menu or a href links in views are handled
I use Arch Linux by the way 

CMS in Action
Reply




Theme © iAndrew 2016 - Forum software by © MyBB