Вызов смарт-компонентов через API SF5
Метод Smart::view() принимает массив, по структуре соответствующий атрибутам тега smart
. Например вызов смарт-компонента в JS:
<smart
name="input"
id="input_email"
templateUrl="/ru/components/simai/"
template="email"
class="test test2 test1337"
events='{"input":[{"sf--input":{"action":"initInput"}}],"ready":[{"sf--input":{"action":"loadEvents"}}]}'
sf_code="input"
data='{"placeholder":"Введите почту","disabled":"true", "required": true, "type": "email"}'
>
</smart>
будет соответствовать вызову смарт-компонента в PHP:
\SIMAI\Main\Smart::view([
'name'=>'input',
'id'=>"input_email",
'templateUrl'=>"/ru/components/simai/",
'template'=>"email",
'class'=>"test test2 test1337",
'events'=>'{"input":[{"sf--input":{"action":"initInput"}}],"ready":[{"sf--input":{"action":"loadEvents"}}]}',
'sf_code'=>"input",
'data'=>'{"placeholder":"Введите почту","disabled":"true", "required": true, "type": "email"}'
]);
Все элементы массива обязательны, кроме "events"
и "templateUrl"
по умолчанию "/ru/components/simai/" если будут какие либо ошибки в переданных данных, они должны будут отобразиться
Примеры вызовов
\SIMAI\Main\Smart::view([
'name'=>'input',
'id'=>"input_email",
'templateUrl'=>"/ru/components/simai/",
'template'=>"email",
'class'=>"test test2 test1337",
'events'=>'{"input":[{"sf--input":{"action":"initInput"}}],"ready":[{"sf--input":{"action":"loadEvents"}}]}',
'sf_code'=>"input",
'data'=>'{"placeholder":"Введите почту","disabled":"true", "required": true, "type": "email"}'
]);
\SIMAI\Main\Smart::view([
'name'=>'input',
'id'=>"input_email_2",
'templateUrl'=>"/ru/components/simai/",
'template'=>"email",
'class'=>"test test2 test1asd",
'events'=>'{"input":[{"sf--input":{"action":"initInput"}}],"ready":[{"sf--input":{"action":"loadEvents"}}]}',
'sf_code'=>"input",
'data'=>'{"placeholder":"Введите почту 2","disabled":"true", "required": true, "type": "email"}'
]);
\SIMAI\Main\Smart::view([
'name'=>'input',
'id' => "phone_input",
'templateUrl'=>"/ru/components/simai/",
'template'=>"phone",
'class'=>"phone-input",
'events'=>'{"input":[{"phone_input":{"action":"validateInput"}}],"ready":[{"phone_input":{"action":"loadEvents"}}, {"phone_input":{"action":"initPhone"}}]}',
'sf_code'=>"input",
'data'=>'{
"placeholder": "e.g. +1 (555) 000 00-00",
"required": true,
"selectedCountry": "RU",
"rightContent": "Right Content",
"helpText": "This is a hint text to help user."
}'
]);
\SIMAI\Main\Smart::view([
'name'=>'textarea',
'id' => "textarea_main",
'templateUrl'=>"/ru/components/simai/",
'template'=>"default",
'class'=>"textarea-default",
'sf_code'=>"textarea",
'events'=>'{"ready":[{"textarea_main":{"action":"loadEvents"}}]}',
'data'=>'{
"label": "Description",
"placeholder": "Enter a description...",
"hint": "This is a hint text to help user.",
"value": "A little about the company and the team that you"
}'
]);
\SIMAI\Main\Smart::view([
'name'=>'pagination',
'id' => "pagination_main",
'templateUrl'=>"/ru/components/simai/",
'template'=>"default",
'class'=>"pagination-default",
'sf_code'=>"pagination",
'data'=>'{"paginate":{"total": 100,"current": 51}}'
]);