• 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Userguide CI 3.0 error

#11
Bug 
I can confirm this. If you will follow the tutorial, you will get this bug. The problem is in News section in the following code:

PHP Code:
<h2><?php echo $title ?></h2>

<?php foreach ($news as $news_item): ?>

        <h3><?php echo $news_item['title'?></h3>
        <div class="main">
                <?php echo $news_item['text'?>
        </div>

        <!-- PROBLEMATIC LINE -->
        <p><a href="news/<?php echo $news_item['slug'?>">View article</a></p>

<?php endforeach ?>

Removing "news/" part works for me, otherwise there are URL's like "/index.php/news/news/something" and they should be like "/index.php/news/something".
PHP Code:
<p><a href="<?php echo $news_item['slug'] ?>">View article</a></p
Reply

#12
There is also confusing PHP declaration in Static pages:
PHP Code:
<?php // confusing declaration, it should not be here
public function view($page 'home')
{

 
   if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
 
   {
 
       // Whoops, we don't have a page for that!
 
       show_404();
 
   }

 
   $data['title'] = ucfirst($page); // Capitalize the first letter

 
   $this->load->view('templates/header'$data);
 
   $this->load->view('pages/'.$page$data);
 
   $this->load->view('templates/footer'$data);


Reply

#13
(02-21-2015, 07:16 AM)Muzikant Wrote: I can confirm this. If you will follow the tutorial, you will get this bug. The problem is in News section in the following code:


PHP Code:
<h2><?php echo $title ?></h2>

<?php foreach ($news as $news_item): ?>

        <h3><?php echo $news_item['title'?></h3>
        <div class="main">
                <?php echo $news_item['text'?>
        </div>

        <!-- PROBLEMATIC LINE -->
        <p><a href="news/<?php echo $news_item['slug'?>">View article</a></p>

<?php endforeach ?>

Removing "news/" part works for me, otherwise there are URL's like "/index.php/news/news/something" and they should be like "/index.php/news/something".

PHP Code:
<p><a href="<?php echo $news_item['slug'] ?>">View article</a></p

So, are you suggesting that $news_item['slug'] itself contains 'news/'?
Reply

#14
(02-21-2015, 07:21 AM)Muzikant Wrote: There is also confusing PHP declaration in Static pages:

PHP Code:
<?php // confusing declaration, it should not be here
public function view($page 'home')
{

 
   if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
 
   {
 
       // Whoops, we don't have a page for that!
 
       show_404();
 
   }

 
   $data['title'] = ucfirst($page); // Capitalize the first letter

 
   $this->load->view('templates/header'$data);
 
   $this->load->view('pages/'.$page$data);
 
   $this->load->view('templates/footer'$data);



Fixed: https://github.com/bcit-ci/CodeIgniter/c...43e15f4dbc
Reply

#15
Bug 
Quote:So, are you suggesting that $news_item['slug'] itself contains 'news/'?

No. There is a list of news on 'http://example.com/index.php/news/'. Each new has its own URL relatively created. Because the URL is created relatively due to 'http://example.com/index.php/news/', then another 'news/' should not be there.

<p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>

It acts like following, which creates wrong URL's and leading to 404 error message:
'http://example.com/index.php/news/' + 'news/' + $news_item['slug'] = 'http://example.com/index.php/news/news/slug'

It should acts like this:
'http://example.com/index.php/news/' + $news_item['slug'] = 'http://example.com/index.php/news/slug'

Routing:
PHP Code:
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view'
Reply

#16
*facepalm*

Yes, we were all thinking only in terms of code and route definitions, and nobody had brought up the current URL for that page ... it does make sense with it. I'll commit the fix shortly.
Reply

#17
Below line:

<p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>

is working when I point the browser to index.php/news

However if I point the browser to index.php/news/ then I need to use

<p><a href="<?php echo $news_item['slug'] ?>">View article</a></p>

Anything we can do to overcome this?
Reply

#18
PHP Code:
<a href="<?php echo site_url('news/' . $news_item['slug']); ?>">View article</a

Then it shouldn't matter what page the link is displayed on, as the URL will be absolute. In fact, I think that's what the current version of the tutorial says should be used.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.