Welcome Guest, Not a member yet? Register   Sign In
url_to not working?
#1

It seems like the built in url_to function isn't working.

Code:
<a class="navbar-brand" href="<?= url_to('Home::index'); ?>">My Site</a>

Home controller:
PHP Code:
<?php

namespace App\Controllers;

class 
Home extends BaseController
{

    public function 
index()
    {
        
$data['title'] = "My Site - Home";
        return 
view('Dashboard/index'$data);
    }



Routing:

PHP Code:
$routes->get('/''Home::index'); 


Error message:

[Image: GtKso4.jpg]
Reply
#2

url_to('App\Controllers\Home::index')
Reply
#3

(03-31-2021, 01:46 PM)paulbalandan Wrote: url_to('App\Controllers\Home::index')

Thanks, it works, but it's not documented that way.
Reply
#4

I have a similar problem. Inside "Controllers" folder I have "Admin" folder. And I can't get path to a controller inside it, it throws the same error.
Code:
<a href="<?= url_to('App\Controllers\Admin\Categories::index') ?>">
Reply
#5

@IvanBell, do you have the folders and file capitalized like in your path?
Code:
app   

└───Controllers
│  │
│  └───Admin
│      │  Categories.php


Did you name the class correctly in your file?
PHP Code:
<?php
namespace App\Controllers;
class 
Categories extends BaseController
{
    public function index()
    {
        return view('categories/index');
    }

Reply
#6

Check the existence of the route.
Reply
#7

Thank you, the problem was with the routes. It was not obvious for me from the docs that url_to() only works if I have the route inside Config/Routes. Lack of experience, I guess
Reply




Theme © iAndrew 2016 - Forum software by © MyBB