Calling the block using php

Permalink Browser Info Environment
Hi - this is a really useful addon - thanks for posting it. We want to run it from php, setting the file set name programmatically. Do you have a code sample to help us along the way?

Thanks again

Type: Discussion
Status: In Progress
View Replies:
mesuva replied on at Permalink Reply
mesuva
Howdy,

if you're wanting to change the way the block outputs the file names, what you need to do is override the block's template, or create a custom block template for it (so you can pick when you use it).

You would need to:
- Create in the top level /application/blocks folder, a folder called list_files_from_set.
- In that, copy in the view.php from the list files from set package and them make changes to that version, which will override what it outputs.

Alternatively, you can create the folder /application/blocks/list_files_from_set/templates and in that copy in the view.php, but rename it to something else. Then you can pick what you've copied in as a custom template when you are editing a block, see -http://www.concrete5.org/documentation/using-concrete5-7/in-page-ed...

If you haven't overridden blocks before, you may need to look up a general guide on how to do that.

-Ryan
seniorb replied on at Permalink Reply
Hi - thanks for that. I probably wasn't clear. What I was after was an example of the parameters for a block call from php - so, for example,
$blockType = BlockType::getByHandle('list_files_from_set');
                              //parameters passed here
$blockType->render('view');

Sorry if it wasn't clear.
mesuva replied on at Permalink Reply
mesuva
Ah, you mean hard-coding the block into a page.

What you have should work, you can adjust settings by adding in before your render line, things like:

$blockType->controller->fileOrder = 'set_order';

For the different things you _might_ be able to adjust, have a look at the db.xml and at the database fields the block uses.

You might also want to look at this blog post as well, it might give you a good example of what to do -http://www.mesuva.com.au/blog/concrete5/creating-a-composer-driven-...

This kind of approach works in 5.6, but I haven't hard coded the block in 5.7 yet. Hopefully the same code still works.
seniorb replied on at Permalink Reply
Hi - just to let anyone who's wanting to do the same know, the code below works ok;
Loader::model('file_set');
                             //get the file set object as $fs
                              $blockType = BlockType::getByHandle('list_files_from_set');
                              $blockType->controller->fsID = $fs->getFileSetID(); // set the file set ID to the ID of the file set object $fs
                              $blockType->controller->numberFiles=10; //set the number of files to display
                              $blockType->controller->paginate='true';
                              $blockType->render('view');

Many thanks for your help and for such a useful addin.

concrete5 Environment Information

# concrete5 Version
5.7.2

# concrete5 Packages
Fruitful (1.1), Like This (0.9.1), List files from set (1.0.7), Login Block (0.9.3), Opt-In Free (0.9.12), Ronyd Expanded Search Bar (2.0), Spacer (0.9.0).

# concrete5 Overrides
blocks/list_files_from_set, languages/el_GR, languages/nl_NL, languages/de_DE, languages/ru_RU, languages/tr_TR, languages/sl_SI, languages/fi_FI, languages/it_IT, languages/da_DK, languages/fr_FR, languages/sv_SE, languages/ja_JP, themes/swiftmail

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - Off
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software
Apache

# Server API
cgi-fcgi

# PHP Version
5.3.29

# PHP Extensions
bcmath, bz2, calendar, cgi-fcgi, Core, ctype, curl, date, dom, ereg, exif, ffmpeg, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, imagick, imap, intl, ionCube Loader, json, libxml, mbstring, mcrypt, mysql, mysqli, OAuth, openssl, pcre, PDO, pdo_mysql, pdo_sqlite, Phar, posix, pspell, Reflection, session, SimpleXML, soap, sockets, SourceGuardian, SPL, SQLite, sqlite3, ssh2, standard, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend Guard Loader, zip, zlib.

# PHP Settings
max_execution_time - 60
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 1000
memory_limit - 256M
post_max_size - 128M
safe_mode - Off
safe_mode_exec_dir - <i>no value</i>
safe_mode_gid - Off
safe_mode_include_dir - <i>no value</i>
sql.safe_mode - Off
upload_max_filesize - 128M
mysql.max_links - Unlimited
mysql.max_persistent - Unlimited
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
session.cache_limiter - <i>no value</i>
session.gc_maxlifetime - 1440
soap.wsdl_cache_limit - 5
safe_mode_allowed_env_vars - PHP_
safe_mode_protected_env_vars - LD_LIBRARY_PATH

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.