• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Libraries Extending Question

#1
I have a Parsedown.php file in my libraries folder

application  > libraries > Parsedown.php


PHP Code:
class Parsedown
{
....


And I want to extend it

application > libraries > MY_Parsedown.php

I tried require but did not make the new changes. How can I extend a library from with in application library and not system libraries.

How can I extend the parsedown into MY_Parsedown.php


PHP Code:
<?php

require APPPATH 'libraries/Parsedown.php';

class 
MY_Parsedown extends Parsedown {
    
    
protected function inlineImage($Excerpt)
    {
        $Inline parent::inlineImage($Excerpt);

        if (!isset($Inline['element']['attributes']['title'])) { return $Inline; }

        $size $Inline['element']['attributes']['title'];

        if (preg_match('/^\d+x\d+$/'$size)) {
            list($width$height) = explode('x'$size);

            $Inline['element']['attributes']['width'] = $width;
            $Inline['element']['attributes']['height'] = $height;

            unset ($Inline['element']['attributes']['title']);
        }

        return $Inline;
    }

Reply

#2
The "MY_" convention you use is the intended convention for extending CodeIgniter's core libraries. You are misusing it. See https://www.codeigniter.com/user_guide/g...core-class

The approach might be reasonable, with slightly different naming. You could make your class "Custom_parsedown", and start it with

Code:
require APPPATH . 'libraries/Parsedown.php';

class Custom_parsedown extends Parsedown {
Reply

#3
(01-12-2017, 09:25 AM)ciadmin Wrote: The "MY_" convention you use is the intended convention for extending CodeIgniter's core libraries. You are misusing it. See https://www.codeigniter.com/user_guide/g...core-class

The approach might be reasonable, with slightly different naming. You could make your class "Custom_parsedown", and start it with

Code:
require APPPATH . 'libraries/Parsedown.php';

class Custom_parsedown extends Parsedown {


I made it work I have had to put the parsedown library in system library folder and  the use MY_Parsedown.php
Reply

#4
(01-12-2017, 02:19 PM)wolfgang1983 Wrote:
(01-12-2017, 09:25 AM)ciadmin Wrote: The "MY_" convention you use is the intended convention for extending CodeIgniter's core libraries. You are misusing it. See https://www.codeigniter.com/user_guide/g...core-class

The approach might be reasonable, with slightly different naming. You could make your class "Custom_parsedown", and start it with

Code:
require APPPATH . 'libraries/Parsedown.php';

class Custom_parsedown extends Parsedown {


I made it work I have had to put the parsedown library in system library folder and  the use MY_Parsedown.php

That would be the wrong thing to do, because if somebody upgrades CodeIgniter and doesn't know that the parsedown library needs to be saved, they'd generally replace the whole system directory and wipe it out. You should just put your extension and parsedown libraries in the application/libraries directory, and do something like this:



PHP Code:
<?php
require_once(APPPATH 'libraries/parsedown.php');
$this->load->library('custom_parsedown');
// ...
$this->custom_parsedown->whatever(); 
Reply

#5
@skunkbad ... aren't we saying the same thing?
Reply

#6
(01-12-2017, 03:21 PM)ciadmin Wrote: @skunkbad ... aren't we saying the same thing?

Need to extend the library though I am going to have to put the parsedown library in system libraryes folder

This way below is not what I am after

Code:
require_once(APPPATH . 'libraries/parsedown.php');
$this->load->library('custom_parsedown');
// ...
$this->custom_parsedown->whatever();
Reply

#7
(01-12-2017, 03:21 PM)ciadmin Wrote: @skunkbad ... aren't we saying the same thing?

We are, but OP is placing the library in the system/libraries directory, so my comment was necessary to reinforce doing things the right way.
Reply

#8
(01-12-2017, 04:19 PM)wolfgang1983 Wrote:
(01-12-2017, 03:21 PM)ciadmin Wrote: @skunkbad ... aren't we saying the same thing?

Need to extend the library though I am going to have to put the parsedown library in system libraryes folder

This way below is not what I am after

Code:
require_once(APPPATH . 'libraries/parsedown.php');
$this->load->library('custom_parsedown');
// ...
$this->custom_parsedown->whatever();

If you're not after doing things the right way, then why ask for help or advice?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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