我在模型Yii中有一个公共函数:
public function test() {
echo 'I am working';
}
Run Code Online (Sandbox Code Playgroud)
现在我想在视图Yii上调用此函数.我喜欢通过控制器而不是在视图Yii上直接调用该函数.
那么如何在视图Yii上调用该函数呢?在我在Yii上调用它之前我和控制器有什么关系?
我正在创建一个表单,将表单的详细信息发送到我的电子邮件.这是我的代码:
<?PHP
$errors = array();
if (isset($_POST["submit"])) {
$to = "myemail@email.com";
$subject = "This is my subject";
$hotel = echo get_permalink();
$headers = array('From: '.$_POST['sendername'].' <'.$_POST['senderEmail'].'>');
//Check the name and make sure that it isn't a blank/empty string.
if(empty($sender)){
//Blank string, add error to $errors array.
$errors['sendername'] = "Please enter your name!";
}
if(empty($senderEmail)){
//Blank string, add error to $errors array.
$errors['senderEmail'] = "Please enter your email!";
}
$mailBody = "<h3>Hotel Details</h3>"
$mail_sent = wp_mail( $to, $subject, $mailBody, $headers ); …Run Code Online (Sandbox Code Playgroud) 我创建了一个元框。代码是:
// Create your custom meta box
add_action( 'add_meta_boxes', 'hotel_amenities' );
// Add a custom meta box to a post
function hotel_amenities( $post ) {
add_meta_box(
'Meta Box Amenities', // ID, should be a string
'Amenities', // Meta Box Title
'amenities_content', // Your call back function, this is where your form field will go
'post', // The post type you want this to show up on, can be post, page, or custom post type
'normal', // The placement of your …Run Code Online (Sandbox Code Playgroud)