Package block runs to another directory php of a file.

Permalink
Hello!

I want to run a file in block another directory

package

directory name

controller.php

directory name

blocks

directory <--- how can run php of a file?
a directory
a.php
b directory
b.php
c directory
c.php

add.php

controller.php

db.xml

form_setup_html.php

view.php


Click select option to choose for a to c of directory at block's form_setup_html

I have made to this select option for pick up directory a or b or c with working. But the files of a, b, c are access denied.

Any ideas on how to work this?

Sorry this is not my first language. I use British Sign Language first.

If any one can help, thank you.

 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You can do this by:

If the directory is a subdirectory of your block, $this->inc() in edit or view.

If the directory is elsewhere in the package, it needs to be /elements, /libraries, /models, /helpers

You can then load correctly named classes or files within those directories using the applicable loader such as
Loader::library('my_class.php', 'package_handle');
$my_class = new MyClass();


Files & classes need to follow the c5 naming conventions for this to work.


If you want to use further directories
Loader::library('another/my_class.php', 'package_handle');
$another_my_class = new AnotherMyClass();


Elements work a bit differently because they are just sequential code, not classes.

There is plenty of info in the documentation.
JSA1972 replied on at Permalink Reply
Great. Thank you very much. I will try. Hope will be work.
JSA1972 replied on at Permalink Reply
I am not sure if I was right.

For example:-

In view.php:-

Loader::library('another/my_class', 'package_handle');
$another_my_class = new AnotherMyClass();

echo $another_my_class;

In package_handle library

my_class.php:-

public function AnotherMyClass(){

$hello = t('Hello');
return $hello;
}

I have test this but error message says 'syntax error, unexpected T_PUBLIC'
JSA1972 replied on at Permalink Reply
I just have found. Remove 'public'

Now working :-)
JSA1972 replied on at Permalink Reply
$this->get ? () for package-->libraries

I can't find this for information from Concrete5 :-(

Anyone can help? Thanks
JSA1972 replied on at Permalink Reply
$_SERVER['DOCUMENT_ROOT'].DIR_REL.'/packages/package_handle/libraries/

Its option select working with the links of libraries folder. I use this code below:-

<?php $dir = $_SERVER['DOCUMENT_ROOT'].DIR_REL.'/packages/package_handle/libraries/'; ?>

<select>

<?php

if ($handle = opendir($dir)) {

while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "<option value='$entry'>".$entry."</option>";
}
}

closedir($handle);
}
?>
</select>