base_url() not getting translated - codeigniter

I have inherited an app that was built with Code Igniter. I've set up the environment and loaded the app on a new machine and I'm having an issue with the call to base_url() not working.
Here is the code as it is in the view:
Start Study Analysis »
When the page is rendered, this is the URL that is created:
Start Study Analysis »
It appears that the function call is not taking place and the code is being inserted as plain text. I've looked at the config.php file and the base_url is set in there. The helper is being loaded in the autoload.php file and I've even tried to load the helper in the view.
Does anyone have any idea as to why this is happening?

Here is the code as it is in the view:
a href="< ?= base_url();?>index.php/study/start">Start Study Analysis » /a>
Either this is a formatting mistake in your post, or you just have a really mangled link there.
I'm going to take a guess that you do have a space between your < and ?=, which would indeed cause the code not to be parsed as php, but instead as broken text/html.
%20 is a url encoded space character, so it makes sense that this is what you'd see in your url.
Make sure there are no spaces in your PHP opening tag:
<?php echo base_url(); ?> and not < ?php echo base_url(); ?>
<?= base_url(); ?> and not < ?= base_url(); ?>
There isn't a space there. I needed to add it [for formatting the post]
The only other thing I can think of is that short tags are not enabled, but I admit that I do not know if this would be your result if that was the case. Try using <?php echo instead of <?=, or enabling the rewrite_short_tags option in your config.php. This certainly is not an issue specific to base_url() or anything similar, your php tags are getting parsed as plain text so what's inside them does not matter at all.

Related

Laravel Blade adds unwanted spaces in final HTML

I'm developing views in Laravel Blade and I always get unwanted spaces in the final HTML (checking with Dev tool) like this (ugly case):
You'll see a lot of unwanted spaces, where the code is simply:
<!-- Ugly -->
<div>
Lorem ipsum
<div>
Lorem ipsum
</div>
</div>
Obviously I've tabulation set as spaces in my IDE.
I tried to remove them in many ways where the only one that works is to put all inline:
<!-- Beautiful (but I can't do this for all!) -->
<div>Lorem ipsum<div>Lorem ipsum</div></div>
but very often I can't do that.
How can avoid all these spaces?
EDIT: this seems to happens in Chrome, not in Firefox
I am noticing this as well. There is interaction between the blade directives and the output formatting/whitespace.
I think what is going on is that the breakpoints in the rendered php occur at the line position of the blade directives. I think this is effectively the desired behaviour though as it is the same behaviour I notice if I use <?php ?> breaks in place of the blade directives.
The way I have worked around this pre-laravel was to zero-indent the <?php ?> breaks, which effectively re-zeros the indent for the contents generated within the <?php ?> braces. This works well and is the most logical way I have found to precisely control the output whitespace from a code readability perspective (though not perfect!).
The equivalent in blade-land appears to be to do the same with blade directives, ie. put them on a new line at position zero. This looks a bit irksome (as it does with regular <?php ?> breaks) but it is the only way I have found to control the output (and I still find regular php to be easier to read and faster to type out than the blade directives for the most part, where you don't need features like $loop).

Processwire Add css class to page

I there a possibility to add a classname to a page?
I can't figure out how to implement such feature or if it already exists.
I'm using Processwire 3.0.42.
Put something like this in your template where the body is:
<body class="<?php echo $page->template->name; ?>">
That will give your page body tag a class equal to page template name.
You can add a page title in the same way.
<body class="<?php echo $page->name; ?>">
Don't be worried about adding a class to every page. The overhead of doing this is negligible.
If you wish to add a different class you would need to add a field to your template and append it to the code above.
As always in ProcessWire, everything is under your control. Alternatives to #ivangretsky's perfectly good answer would include-
Simply include a conditional in your template file. (This doesn't scale well if you need to add other classes to other pages using the same template.)
<?php
$bodyClass = '';
if($page->id == 1021) $bodyClass = 'my-class';
?>
<body class="<?php echo $bodyClass; ?>">
NB Using $page->id is better than $page->name, for example, as the ID doesn't change while the name could.
You could also add a field to the page template definition. Add a field called something like 'Body Class'. Then use the content of that field in your template file.
<body class="<?php echo $page->body-class; ?>">
This will scale better than my other suggestion, and there are options in the ProcessWire backend to hide or partially hide the field during normal use if you don't want users messing with its value.
One 'gotcha' from the CSS spec to be aware of is that CSS identifiers, including class names and IDs cannot start with a digit, so you cannot just use $page->id.
There are lot of options and it depends on your needs and maybe imagination :-).
You can use page name, template name, page id, or maybe combination.
<body class="<?php echo $page->template->name; ?> page-id-<?php echo $page->id; ?>">
// Output
<body class="your-template-name page-id-1234">
This way you can target template, page, or both.
Or, as mentioned by #ivangretsky, you can add custom field to page. And again, you can combine this aproach with template name, etc.
It depends on your needs and what you want to achieve.
Notice:
Using $page->id is better than $page->name, as the ID doesn't change while the name could. #DaveP

Joomla 1.5: $this->countModules returns 1 for Jumi module even when empty

Working on a site in Joomla 1.5! Typically when testing if a module position is empty in Joomla! I'd do something like this:
<?php if ($this->countModules('position')): ?>
BEFORE
<jdoc:include type="modules" name="position" style="xhtml" />
AFTER
<?php endif; ?>
But in my case I have a jumi module that references external source of code.
In some situations it will be blank, which in that case, I don't want the BEFORE and AFTER bits showing either. But whenever I try running the above code, the before and after sections show up, because
$this->countModules() returns 1 instead of 0.
I have "Hide if empty" set to "Yes" for the module, but that doesn't seem to help.
I've even tried setting a return false; on the external source code but that doesn't seem to help either.
Does anybody have any suggestions?
Hide if empty cannot hide the BEFORE and AFTER because it's in the count condition.And BEFORE and AFTER will only hide if no module is enabled for that position. So to hide these you'll have to put this content inside your module.And check the if empty condition.
Let me know if it's not clear.

Codeigniter URL for navigation

I can't figure out how to do the url links.
Basically I have my navigation bar, and I don't know which CodeIgniter URL code to use and how to implement it.
Is what I'm doing here right?:
<?php $this->load->helper('url'); ?>
<li>About Us</li>
I tried to do an anchor like this, but when I load the page it just turns up blank:
<?php echo anchor('views/about.html', 'About Us', title='About Us'); ?>
What am I doing wrong?
There are two ways to make links:
CodeIgniter helper style:
<?php echo anchor('about', 'About us', 'title="About us link"'); ?>
More common HTML with URL echo:
About us
Both will output:
About us
Though if I understand what you are trying to achieve, your mistake is elsewhere.
You don't include the views part, as your URL should point to the controller, not a view. The only case is if you have a controller named views.
CodeIgniter is set up so that it doesn't include file extensions like .html in URL's by default. It does if you've set them up in your config file in $config['url_suffix'] = '';, which is null by default.
See if you've made any of these mistakes.
That is another way on how you do the URL if you are using the URL helper in CI. You should try this, make the base_url() as the value for href. Try this,
About Us
You have to try like this
About Us
or you can give like
About Us
and in the "about" function you put
$this->load->view('about');
but i think the firstone will works for you fine.

CodeIgniter view anchor tag prepending host

In my view I'm trying to create an anchor tag but CodeIgniter is prepending my entire host before what I specify as href, therefor making it invalid.
I put this
My File
I get
My File
EDIT 3
This is my view, I realise i should not be calling a function in my view but in this case I had little option as something needs to get applied for each data item in the loop, I will try to change this but thats beyond my problem right now.
Wesley: I checked the soruce and it displays correctly in the source but in the browser it preappends the host so I guess this has nothing to do with code igniter afterall! How do I make sure it doesn't happen?
<td><?php
$this->ci = &get_instance();
echo $currentData["field_one"] . " - Log"; ?>
</td>
EDIT 4
my html source
<a href="file:://///\\myhost.local.com\120">
View Log
</a>
my url address bar
http://myhost.local.com/myhostlocal/index.php/level/one/type/b/cc/ee/
the url it goes too when I mouse over the href
http:///myhostlocal/index.php/level/one/type/b/cc/ee/file:://///\\myhost.local.com\120
Looks like the browser is treating "file:://///" as a relative path. Why do you have 2 colons, do you need both? Removing one will provide a valid protocol, and the browser will start treating it as an absolute path.

Resources