CodeIgniter Forums
[CLOSED] Learning Custom Url Function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [CLOSED] Learning Custom Url Function (/showthread.php?tid=60815)



[CLOSED] Learning Custom Url Function - El Forum - 07-04-2014

[eluser]riwakawd[/eluser]
I am just learning how to make some custom functions and just trial and error at the moment.

I would like to be able to make in the url helper another function similar to the site_url but called

new $this->url->link(/demo/demo);

Code:
/**
* URL Link
*
* Create a local URL based on your basepath. Segments can be passed via the
* first parameter either as a string or an array.
*
* @access public
* @param string
* @return string
*/
if ( ! function_exists('link'))
{
function link($uri = '')
{
  $CI =& get_instance();
  return $CI->config->link($uri);

  $this->url->link($uri) = $CI->config->link($uri);
}
}

Code:
/**
  *  Link URL
  * Returns base_url . index_page [. uri_string]
  *
  * @access public
  * @param string the URI string
  * @return string
  */
function link($uri = '')
{
  if ($uri == '')
  {
   return $this->slash_item('base_url').$this->item('index_page');
  }

  if ($this->item('enable_query_strings') == FALSE)
  {
   $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
   return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
  }
  else
  {
   return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
  }
}



[CLOSED] Learning Custom Url Function - El Forum - 07-04-2014

[eluser]joergy[/eluser]
Don't understand exactly what Your purpose is....
Normally You write a controller, model, library, view (MVC) and helpers.
Helpers are globally available functions, which must be loaded in your MVC, they are not related to any instances.
On the other hand, if You really want to extend the core, read
http://localhost/CI/general/core_classes.html



[CLOSED] Learning Custom Url Function - El Forum - 07-04-2014

[eluser]riwakawd[/eluser]
[quote author="joergy" date="1404486204"]Don't understand exactly what Your purpose is....
Normally You write a controller, model, library, view (MVC) and helpers.
Helpers are globally available functions, which must be loaded in your MVC, they are not related to any instances.
On the other hand, if You really want to extend the core, read
http://localhost/CI/general/core_classes.html
[/quote]

OK. Which codeigniter was more oop than mvc


[CLOSED] Learning Custom Url Function - El Forum - 07-05-2014

[eluser]CroNiX[/eluser]
Here's an example on how you extend a helper with your own functions, which I believe is the question from your first post: http://ellislab.com/forums/viewthread/245771/#1066946

But you wouldn't access a HELPER with
Code:
$this->url->link(/demo/demo);
like you suggested. You'd access it like
Code:
link('demo/demo');
, as helpers are standalone functions and NOT part of a class. Just like the base_url() function from the url helper isn't $this->url->base_url(). http://ellislab.com/codeigniter/user-guide/general/helpers.html

Not sure what you want your "link" function to do, but the url helper already does have an anchor() function which might be what you're after.

Your last question doesn't make any sense.